import { ConnectionConfig } from "mysql";
import { createDatabaseIfNotExists } from "maishu-node-auth";
import { start as startAdmin } from "maishu-chitu-admin";
import { stationPath, permissions, ServerContentData } from "./website-config";
import { createDataContext } from "./data-context";

interface Settings {
    port: number,
    gateway: string,
    db: ConnectionConfig,
}


export async function start(settings: Settings) {

    await createDatabaseIfNotExists(settings.db);
    await createDataContext(settings.db);

    let serverContextData: ServerContentData = { db: settings.db }
    startAdmin({
        port: settings.port,
        rootDirectory: __dirname,
        station: {
            gateway: settings.gateway,
            path: stationPath,
            permissions: permissions
        },
        serverContextData
    })

}